﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SharpSoft.Data
{
    /// <summary>
    /// 对象的映射名称
    /// </summary>
    [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
    public class MappingNameAttribute : Attribute
    {
        public MappingNameAttribute(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("映射名称不能为空。");
            }
            foreach (var item in name)
            {
                if (!char.IsLetterOrDigit(item) && item!='_')
                {
                    throw new Exception($"映射名称包含无效字符:[{item}]");
                }
            }
            this.Name = name;
        }
        public string Name { get; set; }
    }
}
